import {
  Body,
  Controller,
  Delete,
  Get,
  Param,
  Patch,
  Post,
  Put,
  Req,
} from '@nestjs/common';
import { AuthGuard } from '@nestjs/passport';
import {
  ApiBearerAuth,
  ApiHeader,
  ApiOkResponse,
  ApiOperation,
  ApiTags,
} from '@nestjs/swagger'; // swagger 接口文档
import { Public } from '@/common/decorators/public.decorator';

import { AuthService } from './auth.service';
import { LoginParamsDto } from './auth.dto';

@Controller('auth')
export class AuthController {
  constructor(private readonly authService: AuthService) {}

  //获取验证码
  @Public()
  @Get('/captcha')
  getCaptcha() {
    return this.authService.getCaptcha();
  }

  //注册
  @Public()
  @Post('/register')
  register(@Body() body: LoginParamsDto) {
    return this.authService.register(body);
  }

  //登录
  @Public()
  @Post('/login')
  login(@Body() body: LoginParamsDto) {
    return this.authService.login(body);
  }

  //获取个人信息
  @Get('/userInfo')
  getUserInfo(@Req() req) {
    const userId = req.user.user_id as number;
    return this.authService.getUserInfo(userId);
  }
}
